package 力扣热题100;

public class LeetCode6 {
    public boolean isMatch(String s, String p) {
        for (int i = 0; i < p.length(); i++) {
            if(judge(s,p.substring(i))==true) {
                return true;
            }
        }
        return false;
    }

    private boolean judge(String s, String p) {
        for (int i = 0, k=0; i < s.length(); ) {
            int m=k;
            if(k>=p.length()&&i>=s.length()){
                return true;
            }
            if(k>=p.length()){
                return false;
            }
            if(s.charAt(i)==p.charAt(k)){
                k++;
                i++;
            }
            if(k>=p.length()&&i>=s.length()){
                return true;
            }
            if(k>=p.length()){
                return false;
            }
            if(p.charAt(k)=='.'){
                k++;
                i++;
            }
            if(k>=p.length()&&i>=s.length()){
                return true;
            }
            if(k>=p.length()){
                return false;
            }
            while (k<p.length()&&p.charAt(k)=='*'){
                if(i<s.length()&&k>0&&(s.charAt(i)==p.charAt(k-1)||p.charAt(k-1)=='.')){
                    i++;
                }else {
                    k++;
                }
            }
            if(m==k){
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) {
        LeetCode6 leetCode6=new LeetCode6();
        leetCode6.isMatch("ab", ".*c");
    }
}
